#============================= 添加Python绑定模块
# 创建Python扩展模块
if(NOT pybind11_FOUND)
    message(WARNING "pybind11 not found, skip build python binding")
    return()
endif()

if(FALSE)
# 使用pybind11_add_module创建Python扩展模块
    pybind11_add_module(${MY_PY_BIND}
        MODULE Pybind11.cpp
    )
endif()


##=========================== Python method:
Python_add_library(${MY_PY_BIND} Pybind11.cpp)
##
target_include_directories(${MY_PY_BIND}
    PUBLIC
        ${CMAKE_CURRENT_SOURCE_DIR}
        ${MY_EXPORTS_DIR}
)
## 链接依赖库; 可能需要添加 $env:PYTHONHOME/libs 目录
target_link_directories(${MY_PY_BIND}
    PUBLIC ${Python_LIBRARY_DIRS}
)
target_link_libraries(${MY_PY_BIND}
    PRIVATE
        ${MY_LIB}
    PUBLIC
        pybind11::headers
)

set_target_properties(${MY_PY_BIND} PROPERTIES
    INTERPROCEDURAL_OPTIMIZATION ON
    # CXX_VISIBILITY_PRESET hidden
    # VISIBILITY_INLINES_HIDDEN ON
)


##=========================== 设置模块的输出目录为二进制目录
if(FALSE)
    set_target_properties(${MY_PY_BIND} PROPERTIES
        LIBRARY_OUTPUT_DIRECTORY "${MY_PATH_BIN}"
        RUNTIME_OUTPUT_DIRECTORY "${MY_PATH_BIN}"
    )
endif()

message(STATUS "Successfully configured Python binding module: ${MY_PY_BIND}")

install(TARGETS ${MY_PY_BIND}
    RUNTIME DESTINATION bin
    LIBRARY DESTINATION bin
    ARCHIVE DESTINATION bin
)